<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="经办人编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerId">
              <a-input :disabled=formDisabled v-model="model.handlerId" placeholder="请输入经办人编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经办人部门ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerDeptId">
              <a-input :disabled=formDisabled v-model="model.handlerDeptId" placeholder="请输入经办人部门ID"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经办人部门编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerDeptCode">
              <a-input :disabled=formDisabled v-model="model.handlerDeptCode" placeholder="请输入经办人部门编码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否已删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0" v-model="model.delFlag"
                              placeholder="请输入是否已删除" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同占比（%）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htzb">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0" v-model="model.htzb" placeholder="请输入合同占比"
                              style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ywmc">
              <a-input :disabled=formDisabled v-model="model.ywmc" placeholder="请输入业务名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sctd">
              <a-input :disabled=formDisabled v-model="model.sctd" placeholder="请输入生产团队"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ywfl">
              <a-input :disabled=formDisabled v-model="model.ywfl" placeholder="请输入业务分类"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分配合同额（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fphte">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0" v-model="model.fphte"
                              placeholder="请输入分配合同额" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="团队负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tdfzr">
              <a-input :disabled=formDisabled v-model="model.tdfzr" placeholder="请输入团队负责人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="mainId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainId">
              <a-input :disabled=formDisabled v-model="model.mainId" placeholder="请输入mainId"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'

export default {
  name: 'ErpOmcContractManagerClassFinalForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/api/erp/omc/contractmanager/erpOmcContractManagerClassFinal/add',
        edit: '/api/erp/omc/contractmanager/erpOmcContractManagerClassFinal/edit',
        queryById: '/api/erp/omc/contractmanager/erpOmcContractManagerClassFinal/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
